
<?php session_start(); ?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>充值</title>
    <link href="css/swiper.min.css" rel="stylesheet"/>
    <link href="css/public.css" rel="stylesheet"/>
    <link href="css/main.css" rel="stylesheet"/>
    <link href="css/style.css" rel="stylesheet"/>
    <script src="http://www.jq22.com/jquery/jquery-1.9.1.js"></script>
    <script src="js/swiper.min.js"></script>
    <script src="js/mobile-util.js"></script>
	<script src="https://cdn.bootcss.com/layer/3.1.0/layer.js"></script>
	<script src="js/layer/layer.js"></script>
	<link href="https://cdn.bootcss.com/layer/3.1.0/mobile/need/layer.css" rel="stylesheet">

    <script src="js/public.js"></script>
    <script>
        /*获取url参数*/
        function getUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
            var r = window.location.search.substr(1).match(reg);  //匹配目标参数
            if (r != null) return unescape(r[2]); return null; //返回参数值
        }

        /*获取url参数end*/
    </script>
</head>
<body>

<div class="markbox">
	<img src="img/loading1.gif" />
</div>

<header class="mui-bar mui-bar-nav indexheader flex">
    <div class="headerlogo hide">
        <i class="iconfont backbtn">&#xe602;</i>
    </div>

    <div class="headertitle">
        <p>充值</p>
    </div>

    <div class="headerright">
        <a href="record.html" style="display: none">充值记录</a>
    </div>

</header>


<main class="rechargemain">
    <div class="rechargtop flex">
        <div class="rechargleft">
            <span id="userid">8956 2539 5696</span>
        </div>
        <div class="rechargright">
            <i class="iconfont">&#xe622;</i>
        </div>
    </div>

    <div class="rechargtitle">
        选择充值金额
    </div>
	<!-- <p>系统维护，稍等片刻！</p>-->
	
   <form method="post" action="http://wifi.qianlh.com/weixin/example/index.php" enctype="multipart/form-data">
		<div id="view"></div>
        <ul class="rechargebox">

        	
        </ul>

        <input type="hidden" id="rechargeid" name="rechargeid">
        <input type="hidden" id="rechargeprice" name="rechargeprice">
        <input type="hidden" id="rechargeflow" name="rechargeflow">
		<input type="hidden" id="rechargetuser" name="rechargetuser">
		<input type="hidden" id="rechargepackageid" name="rechargepackageid">
		<input type="hidden" name="url" value="http://wifi.qianlh.com/mobile/priceconfirmation.html">


        <div class="clear"></div>

        <input type="button" value="立即充值"  onclick="callpay1()"  class="rechargebtn"  >
    </form> 
 


</main>




</body>



<script>

	var sn=15465411231;
	var sn1=getUrlParam("device_sn");
    $('#userid').text(sn1);

	var url="http://wifi.qianlh.com";

    var url1=url+"/Mobile/Userapi/user_recharge";


    var loginurl=url+"/Mobile/Userapi/weixin_login";

    $(function () {

		var cce;
		cee = setTimeout(function(){
			$('.markbox').hide();
			clearTimeout(cce);

		}, 1000);


		$.ajax({
			type:'get',
			url:url1+'?device_sn='+sn1,
			success:function(data){
				//console.log(data);

				var data1=JSON.parse(data);
				//console.log(data1);

				/*选择金额end*/

				var code=data1.device_sn;
				//var getcode=data1.code;
				var getsuccess=data1.success;
				//var successcode=code.success;

				if(getsuccess.code == 4000){
					var recharge=code.recharge;

					var str="";
					for(var i=0;i<recharge.length;i++){

						str+='<li data-id="'+recharge[i].id +'" data-packageid="'+recharge[i].package_id +'" data-price="'+recharge[i].price +'" data-flow="'+recharge[i].flow +'">' +
								'<p class="rechargeamount">'+recharge[i].price +'元</p>' +
								'<p class="rechargeprice">'+recharge[i].flow +'</p>' +
								'</li>';
					}

					$('.rechargebox').html(str);
					$('.rechargebox').children("li").eq(0).addClass("cur");
					$('#rechargepackageid').val(recharge[0].package_id);
					$('#rechargeid').val(recharge[0].id);
					$('#rechargeprice').val(recharge[0].price);
					$('#rechargeflow').val(recharge[0].flow);

					var device=code.device;

					if(device[0].user_id==""){
						window.location.href="login.html";
					}
					$('#rechargetuser').val(device[0].user_id);


					/*选择金额*/

					$('.rechargebox li').click(function(){
						$(this).addClass("cur").siblings().removeClass("cur");
						var id=$(this).data().id;
						var price=$(this).data().price;
						var flow=$(this).data().flow;
						var packageid=$(this).data().packageid;
						$('#rechargeid').val(id);
						$('#rechargeprice').val(price);
						$('#rechargeflow').val(flow);
						$('#rechargepackageid').val(packageid);

					});

				}else if(getsuccess.code == 4006){

					layer.open({
						title:false,
						skin:'winning-class',
						area:['70%'],
						content: '<div class="authenticationbox"><p class="authenticationtitle">您还没有实名认证，现在进行认证!</p></div>',
						btn: ['确定'],
						yes: function(index, layero){
							window.location.href='realname.html?device_sn='+sn1;
						},no: function(index, layero){
							window.location.href='realname.html?device_sn='+sn1;
						}
					});




				}else if(getsuccess.code == 4010){
					alert("你的设备号有误！请联系代理！");
					window.opener=null;
					window.open('','_self');
					window.close();
				}


			},
			error:function (data) {
				console.log(data);
					alert("请求失败了");
			}
		});



	});







	function callpay1(){
		var rechargeid=$('#rechargeid').val();
		var rechargeprice=$('#rechargeprice').val();
		var rechargetuser=$('#rechargetuser').val();
		var rechargeflow=$('#rechargeflow').val();
		var rechargepackageid=$('#rechargepackageid').val();
		var device_sn=$('#userid').html();
		// var peam={
		// 	"rechargeid":rechargeid,
		// 	"rechargeprice":rechargeprice,
		// 	"rechargetuser":rechargetuser,
		// 	"rechargeflow":rechargeflow
		// };
        //
		// $.ajax({
		// 	type: 'post',
		// 	url: 'http://wifi.qianlh.com/weixin/example/jsapi.php',
		// 	data:peam,
		// 	success: function (data) {
		// 		console.log(data);
		// 	},error:function(data){
		// 		console.log(data);
		// 	}
		// });
		// return false;

		console.log(rechargepackageid);
		var newurl=url+"/mobile/priceconfirmation.html?rechargeprice="+rechargeprice+"%26device_sn="+device_sn;
		//var newurl="http://www.so.com/s?src=srp%26fr=360chrome_newtab_search%26psid=8e590c535e2875d919fc25f88851272d";
		// return false;
		window.location.href="http://wifi.qianlh.com/weixin/example/index.php?rechargeid="+rechargeid+
		"&rechargeflow="+rechargeflow+"&rechargetuser="+rechargetuser+"&rechargepackageid="+rechargepackageid+"&url="+newurl+"&rechargeprice="+rechargeprice+"&device_sn="+device_sn;
	}












</script>


</html>
